<template>
  <div class="eadd">
    <el-card class="box-card">
      <el-button
        class="submission priamry_border"
        style="display: flex; float: right"
        @click="back()"
        >返回</el-button
      >
      <div class="title">{{ roomid ? "编辑记录" : "添加记录" }}</div>
      <div style="margin: 15px 0"><hr /></div>
      <!-- 表单 -->
      <el-form
        ref="formValidate"
        class="frame"
        :inline="true"
        :rules="rules"
        :model="roominfolist"
        label-width="120px"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="记录人id:" prop="authorId">
              <el-input
                v-model="roominfolist.authorId"
                maxlength="120"
                placeholder="请输入记录人id"
              /> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="记录人名称：" prop="authorName">
              <el-input
                v-model="roominfolist.authorName"
                maxlength="120"
                placeholder="请输入记录人名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="创建时间">
              <el-date-picker
                value-format="yyyy-MM-dd HH:mm:ss"
                v-model="roominfolist.createTime"
                type="datetime"
                placeholder="选择创建日期时间"
                style="width:400px"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="更新时间">
              <el-date-picker
                value-format="yyyy-MM-dd HH:mm:ss"
                v-model="roominfolist.updateTime"
                type="datetime"
                placeholder="选择更新日期时间"
                style="width:400px"
              >
              </el-date-picker> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="id:" prop="id">
              <el-input
                v-model="roominfolist.id"
                maxlength="120"
                placeholder="请输入id"
              /> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="状态：" prop="status">
              <el-switch
                disabled
                v-model="roominfolist.status"
                :active-value="roominfolist.status === 0"
                :inactive-value="roominfolist.status === 1"
              >
              </el-switch> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="业务id:" prop="ywid">
              <el-input
                v-model="roominfolist.ywid"
                maxlength="120"
                placeholder="请输入业务id"
              /> </el-form-item
          ></el-col>
          <el-col :span="12">
            <el-form-item label="记录内容:" prop="content">
              <el-input
                v-model="roominfolist.content"
                maxlength="120"
                placeholder="请输入记录内容"
              /> </el-form-item
          ></el-col>
          <el-col :span="12">
            <div class="fjBed">
              <span>选择记录类型：</span>
              <el-select
                v-model="roominfolist.type"
                placeholder="选择记录类型"
                style="width: 400px;"
              >
                <el-option
                  v-for="item in optionsbad"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </el-col>
        </el-row>
        <span class="textarea">
          <el-form-item label="记录标题：" prop="title">
            <span>
              <el-input
                type="textarea"
                v-model="roominfolist.title"
                maxlength="240"
                placeholder="请输入记录标题"
              />
            </span>
          </el-form-item>
        </span>

        <div style="margin-left: 120px">
          <el-button type="primary" class="submission" @click="eadd(roomid)"
            >确定</el-button
          >
        </div>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { addbusinessApi } from "@/api/businessRecord";

export default {
  data() {
    return {
      // 记录类型
      optionsbad: [
        {
          value: 0,
          label: "异常错误记录"
        },
        {
          value: 1,
          label: "系统(定时任务)"
        },
        {
          value: 2,
          label: "管理员操作"
        },
        {
          value: 3,
          label: "商家操作"
        },
        {
          value: 4,
          label: "用户操作"
        },
        {
          value: 5,
          label: "游客"
        }
      ],
      //验证规则
      rules: {
        // //房间类型
        // fjType: [
        //   { required: true, message: "请输入房间类型", trigger: "blur" }
        // ],
        // //饮品
        // drink: [{ required: true, message: "请输饮品", trigger: "blur" }],
        // //房间设施
        // facility: [
        //   { required: true, message: "请输入房间设施", trigger: "blur" }
        // ],
        // //房间面积：
        // fjArea: [
        //   { required: true, message: "请输入房间面积", trigger: "blur" }
        // ],
        // //房间密码
        // fjPwd: [{ required: true, message: "请输入房间密码", trigger: "blur" }],
        // //商品床型
        // fjBedType: [
        //   { required: true, message: "请输入商品床型", trigger: "blur" }
        // ],
        // //卫生间信息
        // fjToilet: [
        //   { required: true, message: "请输入卫生间信息", trigger: "blur" }
        // ],
        // //房型名称
        // fxName: [
        //   { required: true, message: "请选择房型名称", trigger: "blur" }
        // ],
        // //房间窗户信息
        // fjWindows: [
        //   { required: true, message: "请输入房间窗户信息", trigger: "blur" }
        // ],
        // //容纳人数
        // galleryful: [
        //   { required: true, message: "请输入容纳人数", trigger: "blur" }
        // ],
        // //洗漱用品
        // wash: [{ required: true, message: "请输入洗漱用品", trigger: "blur" }],
        // //备注
        // remark: [{ required: true, message: "请填写备注", trigger: "blur" }],
        // recreation: [
        //   { required: true, message: "请输入娱乐设备", trigger: "blur" }
        // ]
      },
      //eadd数据源
      roominfolist: {
        authorId: "", //记录人id
        authorName: "", //记录人名称
        content: "", //记录内容
        createTime: "", //创建时间
        id: "", //id
        status: "", //状态
        title: "", //记录标题
        type: "", //记录类型
        updateTime: "", //更新时间
        ywid: "" //业务id
      },
      //传过来的id
      roomid: "",
      pagesize: {
        // 每页数量
        limit: 20,
        // 页码
        page: 1
      },
      //查询所有酒店
      hotalForm: {
        limit: 10,
        page: 1
      },
      //选择酒店
      options: [],
      value: ""
    };
  },
  created() {
    // this.gethotalList();
  },
  mounted() {
    if (this.$route.params.id) {
      this.roomid = this.$route.params.id;
      this.loadData(this.$route.params.id, "roomid");
    }
  },
  methods: {
    //添加修改
    async eadd(roomid) {
      this.$refs.formValidate.validate(async valid => {
        if (!valid) return;
        // 修改
        if (roomid) {
          console.log(this.roominfolist, "修改");
          // await eidtRoominfoilApi(this.roominfolist);
          this.$message.success("修改成功");
        } else {
          // 新增
          const res = await addbusinessApi(this.roominfolist);
          console.log("新增成功", res);
          this.$message.success("新增成功");
        }
        this.$router.push("/amszs/businessRecord/index");
      });
    },
    // 返回
    back() {
      this.$router.go(-1);
    },
    // 根据id查渲染
    async loadData(roomid) {
      const res = await RoominfoDetailApi({ id: roomid });
      this.roominfolist = res;
      console.log("roominfolist", this.roominfolist);
    }
  }
};
</script>

<style lang="scss" scoped>
.eadd {
  padding: 20px;
  .fjBed {
    font-weight: 700;
    margin-left: 23px;
    margin-bottom: 20px;
    span {
      margin-right: 10px;
    }
  }
  .textarea {
    .el-form-item :last-child {
      width: 400px;
    }
  }

  .title {
    font-weight: 700;
    font-size: 20px;
  }
  .frame {
    .el-form-item {
      .el-input {
        width: 400px;
      }
      .el-select {
        width: 70px;
      }
    }
  }
  .upload {
    display: flex;
    width: 800px;
    height: 100px;
    .pictrue {
      width: 60px;
      height: 60px;
      border: 1px dotted rgba(0, 0, 0, 0.1);
      margin-right: 10px;
      position: relative;
      cursor: pointer;
    }
    .img {
      width: 60px;
      height: 60px;
    }
    .btndel {
      position: absolute;
      z-index: 11111;
      width: 20px !important;
      height: 20px !important;
      left: 46px;
      top: -4px;
    }
  }
}
</style>
